home *** CD-ROM | disk | FTP | other *** search
- // Copyright (c)1995 Ray Dream, Inc. All Rights Reserved.
- /* $Id: COMGEL.cpp 1.5 1997/04/10 23:29:09 damien Exp $ */
-
- ////////////////////////////////////////////////////////////////////////
- // First Gel Example : Gel Light //
- //--------------------------------------------------------------------//
- // Implementation of the Gel Interface //
- ////////////////////////////////////////////////////////////////////////
-
- #include "math.h"
-
- #ifndef __COMGEL__
- #include "COMGEL.h"
- #endif
-
- #ifndef __GELDLL__
- #include "GelDLL.h"
- #endif
-
- #ifndef __3DCOFAIL__
- #include "3DCoFail.h"
- #endif
-
- #undef INTERFACE
- #define INTERFACE GelLight
-
- // Constructor / Destructor of the C++ Object :
- GelLight::GelLight() {
- fCRef=0; // Reference counter
- // Data initialization :
- fData.fNbBranches=5;
- }
-
- GelLight::~GelLight() {
- global_count_Obj--;
- }
-
- // IUnknown Interface :
- HRESULT GelLight::QueryInterface(THIS_ REFIID riid,LPVOID* ppvObj) {
- *ppvObj=NULL;
-
- // The GelLight knows the interfaces of the parent Objects
- if (IsEqualIID(riid, IID_IUnknown))
- *ppvObj=(LPVOID)this;
- else if (IsEqualIID(riid, IID_I3DExLightsourceGel))
- *ppvObj=(LPVOID)this;
- else if (IsEqualIID(riid, IID_I3DExDataExchanger))
- *ppvObj=(LPVOID)this;
- else if (IsEqualIID(riid, IID_I3DExtension))
- *ppvObj=(LPVOID)this;
-
- // we must add reference if we return an interface
- if (*ppvObj!=NULL) {
- ((LPUNKNOWN)*ppvObj)->AddRef();
- return NOERROR;
- }
- else {
- return ResultFromScode(E_NOINTERFACE);
- }
- }
-
- ULONG GelLight::AddRef(THIS) {
- return fCRef++;
- }
-
- ULONG GelLight::Release(THIS) {
- ULONG UnreleaseObject=fCRef--;
-
- if (fCRef==0)
- delete this; // No reference left so delete the object
-
- return UnreleaseObject;
- // Use local variable because if the object is destructed
- // fCRef do not exist
- }
-
- // I3DExtension methods :
- I3DExtension* GelLight::Clone(THIS) {
- GelLight* theClone = new GelLight;
- if (theClone) {
- theClone->AddRef();
- theClone->fData=fData;
- }
- return theClone;
- }
-
- HRESULT GelLight::ShellUtilitiesInit(THIS_ IShUtilities* shellUtilities) {
- InitCoFailure(shellUtilities);
- return NOERROR;
- }
-
-
- // I3DExDataExchanger methods :
- ExtensionDataMap* GelLight::GetExtensionDataMap(THIS) {
- return NULL;
- }
-
- void* GelLight::GetExtensionDataBuffer(THIS) {
- return &fData; // The Shell uses this pointer to set the values of the Gel's parameters
- }
-
- HRESULT GelLight::ExtensionDataChanged(THIS) {
- return NOERROR;
- }
-
- HRESULT GelLight::HandleEvent(THIS_ ULONG SourceID) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- short GelLight::GetResID(THIS) {
- return 133; // This is the view ID in the resource file
- }
-
- NUM3D kPI=3.1415926535897932384626233;
-
- // I3DExLightsourceGel methods :
- BOOLEAN GelLight::GetGelValues(THIS_ VECTOR2D* gelScreenPosition,COLOR3D* result) {
- NUM3D alpha;
- NUM3D graylevel;
- alpha=atan2((*gelScreenPosition)[1],(*gelScreenPosition)[0]); //QuickArcSinCos((*gelScreenPosition)[1],(*gelScreenPosition)[0],alpha);
- alpha*=fData.fNbBranches;
-
- while (alpha<0.0) alpha+=kPI*2.0; // Modulo 2 pi
- while (alpha>kPI*2.0) alpha-=kPI*2.0; // Modulo 2 pi
-
- if (alpha<kPI/2.0) {
- graylevel=1.0-alpha/(kPI/2.0);
- }
- else if (alpha>kPI*1.5) {
- graylevel=(alpha-kPI*1.5)/(kPI/2.0);
- }
- else {
- graylevel=0.0;
- }
-
- result->Mode=0;
- result->R=graylevel;
- result->G=graylevel;
- result->B=graylevel;
-
- return TRUE;
- }
-